package com.wwj.my_ummary.util;

import java.io.*;

/**
 * 序列化工具类
 *
 * @author Administrator
 */
public class SerUtils {

    public static byte[] serializeObj(Object obj) {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            byte[] bytes = baos.toByteArray();
            return bytes;
        } catch (IOException e) {
            System.out.println(8);
            return null;
        }
    }

    public static Object unserializeObj(byte[] bytes) {
        ByteArrayInputStream bais = null;
        try {
            bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais);
            return ois.readObject();
        } catch (Exception e) {
            return null;
        }

    }

}
